<template>
  <div class="index-box">
    <el-row>
      <el-col :span="12">
        <div class="grid-content">
          <p>{{userName.replace(/^\'|\'$/g, '')}}</p>
          <p>{{userRole}}</p>
        </div>
      </el-col>
      <el-col :span="12">
        <div class="grid-content">
          <p>最近登录时间</p>
          <p>{{latestLoginTime}}</p>
        </div>
      </el-col>
    </el-row>
  </div>
</template>
<script>
  // import axios from 'axios'
  import {mapGetters, mapActions} from 'vuex'
  export default{
    name: 'index-box',
    data () {
      return {
        latestLoginTime: '',
        userName: '',
        userRole: ''
      }
    },
    computed: {
      // 映射State
      ...mapGetters([
        'apiUrl', 'isLogin', 'roleId'
      ])
    },
    methods: {
      ...mapActions([
        'getStorage'
      ])
    },
    mounted () {
      this.getStorage('latestLoginTime').then((latestLoginTime) => {
        this.latestLoginTime = latestLoginTime
      }, function (error) {
        console.log(error)
      })
      this.getStorage('userName').then((userName) => {
        this.userName = userName
      }, function (error) {
        console.log(error)
      })
      this.getStorage('userRole').then((userRole) => {
        this.userRole = userRole
      }, function (error) {
        console.log(error)
      })
    }
  }
</script>
<style scoped lang='less'>
  .index-box {
    margin-top: 180px;
    .el-col {
      border-radius: 4px;
    }
    .grid-content {
      border-radius: 4px;
      min-height: 36px;
      border: 1px solid #eee;
      p {
        text-align: center;
      }
    }
    .row-bg {
      padding: 10px 0;
    }
  }
</style>
